import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
import store from './store'
import $ from 'jquery' // 上传图片用
import BaiduMap from 'vue-baidu-map'

import '@/permission'

Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: 'S3iZzz0HB4BlBLaH9fxgugdp2qFtlKsK'
})

window.jQuery = $
window.$ = $

import * as echarts from "echarts";
Vue.prototype.$echarts = echarts



Vue.config.productionTip = false
Vue.use(ElementUI);

// 全局修改message持续时间
import { Message } from 'element-ui';
Vue.prototype.$message = function (msg) {
  Message(msg)
}
Vue.prototype.$message = function (msg) {
  return Message({
    message: msg,
    duration: 1000
  })
}
Vue.prototype.$message.success = function (msg) {
  return Message.success({
    message: msg,
    duration: 1000
  })
}
Vue.prototype.$message.warning = function (msg) {
  return Message.warning({
    message: msg,
    duration: 1000
  })
}
Vue.prototype.$message.error = function (msg) {
  return Message.error({
    message: msg,
    duration: 1000
  })
}

/**
 * to: 到哪个页面去
 * from: 从哪个页面来
 * next: 直接放行
 * next({ name: xx }): 跳转
 */
// router.beforeEach((to, from, next) => {
//   document.title = '失物招领平台'
// 	if(to.name === 'login' || to.name === 'register' || to.name === 'forgetPasswd') {
// 	    if(Cookie.get("token") === undefined) {
// 	        next();
//         } else {
//             next({name:'all'})
//         }
// 	} else {
// 		if(Cookie.get("token") !== undefined) {
// 		    let user = JSON.parse(Cookie.get("user"))
//             // console.log("user",user.role)
//             // console.log("to::",to.name)
//             if(user.role === 'user' && (to.name === 'adminIndex' || to.name === 'adminhome' || to.name === 'userManger' || to.name === 'unpostManger' || to.name === 'noticeManger' || to.name === 'postManger' || to.name === 'goodstypeManger')){
//                 next({name:'all'})
//                 //console.log("无权限访问")
//             }
// 		    else{
//                 next();
//             }
// 		} else {
// 			next({name: 'login'})
// 		}
// 	}
// })

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
